package com.example.authsystem.service;

import com.example.authsystem.entity.AuditLog;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Tag(name = "审计业务服务", description = "系统审计和日志服务接口")
@Hidden
public interface AuditService {

    // 用户行为审计
    @Operation(summary = "记录用户登录", description = "记录用户登录行为日志", hidden = true)
    @ApiResponse(responseCode = "200", description = "记录成功")
    void logUserLogin(
            @Parameter(description = "用户名", required = true) String username,
            @Parameter(description = "登录IP地址", required = true) String ipAddress,
            @Parameter(description = "设备标识") String deviceId,
            @Parameter(description = "登录位置") String location
    );

    @Operation(summary = "记录用户登出", description = "记录用户登出行为日志", hidden = true)
    void logUserLogout(
            @Parameter(description = "用户名", required = true) String username,
            @Parameter(description = "会话时长(分钟)") Long sessionDuration
    );

    @Operation(summary = "记录用户注册", description = "记录用户注册行为日志", hidden = true)
    void logUserRegistration(
            @Parameter(description = "用户名", required = true) String username,
            @Parameter(description = "邮箱地址", required = true) String email,
            @Parameter(description = "注册IP地址") String ipAddress
    );

    @Operation(summary = "记录用户资料更新", description = "记录用户资料更新行为日志", hidden = true)
    void logUserProfileUpdate(
            @Parameter(description = "用户ID", required = true) Long userId,
            @Parameter(description = "更新的字段") Map<String, Object> changedFields,
            @Parameter(description = "操作者用户名") String operatorUsername
    );

    // 系统访问审计
    @Operation(summary = "记录仪表板访问", description = "记录仪表板页面访问日志", hidden = true)
    void logDashboardAccess();

    @Operation(summary = "记录用户列表访问", description = "记录用户列表查询日志", hidden = true)
    void logUserListAccess(
            @Parameter(description = "页码") int page,
            @Parameter(description = "每页大小") int size,
            @Parameter(description = "搜索关键词") String keyword
    );

    @Operation(summary = "记录用户活动查询", description = "记录用户活动统计查询日志", hidden = true)
    void logUserActivityQuery(
            @Parameter(description = "开始日期", required = true) LocalDate startDate,
            @Parameter(description = "结束日期", required = true) LocalDate endDate
    );

    @Operation(summary = "记录系统指标访问", description = "记录系统性能指标访问日志", hidden = true)
    void logSystemMetricsAccess();

    @Operation(summary = "记录报表导出", description = "记录统计报表导出操作日志", hidden = true)
    void logReportExport(
            @Parameter(description = "报表类型", required = true) String reportType,
            @Parameter(description = "开始日期", required = true) LocalDate startDate,
            @Parameter(description = "结束日期", required = true) LocalDate endDate
    );

    // 统计查询方法
    @Operation(summary = "获取总登录次数", description = "获取系统总登录次数统计", hidden = true)
    @ApiResponse(responseCode = "200", description = "查询成功",
            content = @Content(schema = @Schema(implementation = Long.class)))
    long getTotalLoginCount();

    @Operation(summary = "获取每日登录次数", description = "获取指定日期的登录次数", hidden = true)
    long getDailyLoginCount(
            @Parameter(description = "查询日期", required = true) LocalDate date
    );

    @Operation(summary = "获取每日活跃用户数", description = "获取指定日期的活跃用户数", hidden = true)
    long getDailyActiveUserCount(
            @Parameter(description = "查询日期", required = true) LocalDate date
    );

    @Operation(summary = "获取功能使用统计", description = "获取各功能模块的使用统计", hidden = true)
    @ApiResponse(responseCode = "200", description = "查询成功")
    Map<String, Long> getFeatureUsageStats();

    @Operation(summary = "获取审计日志列表", description = "分页获取审计日志记录", hidden = true)
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "查询成功"),
            @ApiResponse(responseCode = "400", description = "参数错误")
    })
    List<AuditLog> getAuditLogs(
            @Parameter(description = "页码", required = true) int page,
            @Parameter(description = "每页大小", required = true) int size,
            @Parameter(description = "操作类型过滤") String actionType,
            @Parameter(description = "开始日期") LocalDate startDate,
            @Parameter(description = "结束日期") LocalDate endDate
    );

    @Operation(summary = "清理过期日志", description = "清理指定天数之前的审计日志", hidden = true)
    void cleanupExpiredLogs(
            @Parameter(description = "保留天数", required = true) int retentionDays
    );
}
